#include "PlatformDelimiter.h"


// Material Properties
GLfloat platform1_diffuse[] = {0.60, 0.60, 0.60, 1.0};
GLfloat platform2_diffuse[] = {0.50, 0.50, 0.50, 1.0};
GLfloat platform3_diffuse[] = {0.40, 0.40, 0.40, 1.0};

PlatformDelimiter::PlatformDelimiter(void)
{	
	glColor3f(1,1,1);
	baseBottomWidth = (GLfloat) 1/4;
	baseBottomHeight = (GLfloat) 1/3;
	baseTopWidth = (GLfloat) 1/7;
	baseTopHeight = (GLfloat) 1/3;
	antena1Height = (GLfloat) 1/3;
	antena2Height = (GLfloat) 1/5;
	antenaRadius = (GLfloat) 0.0105;
	quad = gluNewQuadric();

	//load the images to use as textures
	Image* image1 = loadBMP("textures\\granite.bmp");
	Image* image2 = loadBMP("textures\\marble.bmp");
	Image* image3 = loadBMP("textures\\cement.bmp");
	blockTexture = loadTexture(image1);
	midTexture = loadTexture(image2);
	rodTexture = loadTexture(image3);
	delete image1;
	delete image2;
	delete image3;
}

void PlatformDelimiter::display(int up, int left)
{
	
	glPushMatrix();
		glTranslatef(-0.15, 0.5, -0.10);

		glRotatef((GLfloat) left, 0.0, 1.0, 0.0);
		glRotatef((GLfloat) up, 1.0, 0.0, 0.0);	

		// draw bottom base block
		glMaterialfv(GL_FRONT, GL_DIFFUSE, platform1_diffuse);
		glColor3f(0.6,0.6,0.6);
		glPushMatrix();	
			glBindTexture(GL_TEXTURE_2D, midTexture);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
			glScalef(baseBottomWidth, baseBottomHeight, baseBottomWidth);
			glTranslatef(0.5, 0.5, 0.5);
			DefaultCube::display();
		glPopMatrix();

		// draw TOP base block
		glMaterialfv(GL_FRONT, GL_DIFFUSE, platform2_diffuse);
		glColor3f(0.5,0.5,0.5);
		glPushMatrix();	
			//create the texture for the top block, set to 'marble'
			glBindTexture(GL_TEXTURE_2D, midTexture);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
			glTranslatef(baseBottomWidth/5, baseBottomHeight, baseBottomWidth/5);
			glScalef(baseTopWidth, baseTopHeight, baseTopWidth);
			glTranslatef(0.5, 0.5, 0.5);
			DefaultCube::display();
		glPopMatrix();

		glMaterialfv(GL_FRONT, GL_DIFFUSE, platform3_diffuse);
		glColor3f(0.4,0.4,0.4); //antena color

		//create the texture for the rods on top of the blocks to "cement" and wrap it around the cylinders
		glBindTexture(GL_TEXTURE_2D, rodTexture);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

		// draw antena 1 (the big one)
		glPushMatrix();
			glTranslatef(baseTopWidth, baseBottomHeight + baseTopHeight, baseTopWidth);
			gluQuadricNormals(quad, GLU_SMOOTH);
			gluQuadricTexture(quad, GL_TRUE);		//enable texture coordinates
			glRotatef(-90, 1,0,0);
			gluCylinder(quad, antenaRadius, antenaRadius, antena1Height, 10, 30);
		glPopMatrix();

		// draw antena 2 (the small one)
		glPushMatrix();
			glTranslatef(baseTopWidth/1.2, baseBottomHeight + baseTopHeight, baseTopWidth);
			gluQuadricNormals(quad, GLU_SMOOTH);
			gluQuadricTexture(quad, GL_TRUE);		//enable texture coordinates
			glRotatef(-90, 1,0,0);
			gluCylinder(quad, antenaRadius, antenaRadius, antena2Height, 10, 30);
		glPopMatrix();
	glPopMatrix();
}

PlatformDelimiter::~PlatformDelimiter(void)
{
}
